/**
 * Created by wzh on 2016/6/23.
 */
'use strict';
swan_pc
    .factory('Category', function ($resource) {
        return $resource('/api/categories', {id:'cid'}, {
            'query': { method: 'GET', isArray: true}
        });
    })
    .factory("tagSetByOrg",function($resource){
        return $resource("api/tag-sets/:id/organization",{id:"@id"},{
            "query":{
                method:"GET",
                isArray:true
            }
        })
    })
    .factory('OrgContactInfo', function ($resource, DateUtils) {
        return $resource('/api/v2/orgContacts/findByEO/:infoid', {infoid:'@infoid'}, {
            "query":{
                method:"GET",
                isArray:true
            },
            "queryAll":{
                method:"GET",
                isArray:true,
                url:"/api/v2/orgContacts/getAllOrgContactByEOAndOpp"
            },
            "save":{
                method:"POST",
                url:"/api/v2/org_contacts"
            },
            "update":{
                method:"PUT",
                url:"/api/v2/org_contacts"
            },
            "queryOne":{
                method:"GET",
                url:"/api/v2/org_contacts/:cid"
            }
        })
    })
    .factory('ContactInfo', function ($resource, DateUtils) {
        return $resource('/api/v2/user_contacts/:infoid', {infoid:'@infoid'}, {
            "filter":{
                method:"POST",
                isArray:true,
                url:"/api/v2/userContacts/filter"
            },
            'query': {
                method: 'GET',
                isArray: true,
                url:"/api/v2/user_contacts3"
            },
            'queryAll': {
                method: 'GET',
                transformResponse: function (data) {
                    data = angular.fromJson(data);
                    //data.baseInfo.birthDate = DateUtils.convertLocaleDateFromServer(data.baseInfo.birthDate);
                    return data;
                }
            },
            'get': {
                method: 'GET',
                transformResponse: function (data) {
                    data = angular.fromJson(data);
                    //data.birthDate = DateUtils.convertLocaleDateFromServer(data.birthDate);
                    return data;
                }
            },
            'update': {
                method: 'PUT',
                transformRequest: function (data) {
                    //data.birthDate = DateUtils.convertLocaleDateToServer(data.birthDate);
                    return angular.toJson(data);
                }
            },
            'save': {
                method: 'POST',
                transformRequest: function (data) {
                    data.birthDate = DateUtils.convertLocaleDateToServer(data.birthDate);
                    return angular.toJson(data);
                }
            },
            'delete':{
                method:'DELETE'
            },
            'linkup':{
                method:'POST',
                url:"/api/v2/user_contacts/:infoid/link_up",
                isArray:true
            },
            'linkDown':{
                method:'POST',
                url:"/api/v2/user_contacts/link_down",
            },
            'breakLink':{
                method:'POST',
                url:"/api/v2/user_contacts/:infoid/break_link",
            },
            'linkupConfirm':{
                method:'POST',
                url:"/api/v2/user_contacts/:infoid/link_up_confirm",
            }
        });
    });